package swu.cx.flowgroup

import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.Gravity
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView

class myViewGroup:LinearLayout {
    var layoutImgId = R.drawable.wiwi
    var layoutText = "唯玖依依"
    constructor(context: Context):super(context){
        initView()
    }
    constructor(context: Context,attr:AttributeSet):super(context,attr){
        val typedArray:TypedArray = context.obtainStyledAttributes(attr,R.styleable.myViewGroup)
        layoutImgId = typedArray.getResourceId(R.styleable.myViewGroup_layoutPic,R.drawable.wiwi)
        layoutText = typedArray.getString(R.styleable.myViewGroup_layoutText)!!
        initView()
    }
    private fun initView(){
        orientation = VERTICAL
        gravity = Gravity.CENTER_HORIZONTAL
        ImageView(context).apply {
            layoutParams = LayoutParams(200,200)
            setImageResource(layoutImgId)
            addView(this,layoutParams)
        }
        TextView(context).apply {
            gravity = Gravity.CENTER_HORIZONTAL
            layoutParams = LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT).apply {
                topMargin = 50
            }
            text = layoutText
            addView(this,layoutParams)
        }

    }
}